//-----------------------------------------------------------------------
// <copyright file="PseudoBuildEngine.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Andy Reeves</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>This is our Pseudo BuildEngine Class.</summary>
//-----------------------------------------------------------------------

namespace Microsoft.Sdc.Tasks
{
    using System;
    using System.IO;
    using System.Reflection;
    using System.Collections;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;

    /// <summary>
    /// This is our Pseudo BuildEngine Class
    /// this lets us call task execute methods from outside msbuild
    /// Must implement these methods:
    ///         BuildProjectFile
    ///         LogBuildEvent
    ///         GetDescriptiveErrorMessage
    ///         
    /// </summary>
    sealed internal class PseudoBuildEngine : IBuildEngine
    {
        private string lastMessage;
        private string previousMessage;

        public string LastMessage
        {
            get { return this.lastMessage; }
        }

        public string PreviousMessage
        {
            get { return this.previousMessage; }
        }

        private int messages = 0;
        private int warnings = 0;
        private int errors = 0;
        private string log = "";

        internal int Messages
        {
            set { this.messages = value; }
            get { return this.messages; }
        }

        internal int Warnings
        {
            set { this.warnings = value; }
            get { return this.warnings; }
        }

        internal int Errors
        {
            set { this.errors = value; }
            get { return this.errors; }
        }

        public void LogErrorEvent(BuildErrorEventArgs eventArgs)
        {
            this.previousMessage = this.lastMessage;
            this.lastMessage = eventArgs.Message;
            Console.WriteLine(eventArgs.Message);

            throw new ApplicationException("PseudoEngineException");
        }

        public void LogWarningEvent(BuildWarningEventArgs eventArgs)
        {
            Console.WriteLine(eventArgs.Message);
        }

        public void LogCustomEvent(CustomBuildEventArgs eventArgs)
        {
        }

        public void LogMessageEvent(BuildMessageEventArgs eventArgs)
        {
            Console.WriteLine(eventArgs.Message);
        }

        public bool ContinueOnError
        {
            get { return false; }
        }

        public string ProjectFileOfTaskNode
        {
            get { return String.Empty; }
        }

        public int LineNumberOfTaskNode
        {
            get { return 0; }
        }

        public int ColumnNumberOfTaskNode
        {
            get { return 0; }
        }

        internal string Log
        {
            set { this.log = value; }
            get { return this.log; }
        }

        public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs)
        {
            return false;
        }
    }
}
